<?php 
/* This is a tool box used for testing & dev purposes from the command line
 such as 

 % php utils.php

 To use it, copy it to its parent dir (..), then run it.

*/

require_once 'appinclude.php';
require_once 'yubi_lib.php';
require_once '../wsapi/common.php';

///// Generate an API key to sign/verify OTP validation requests & responses
//

echo "\nAPI Key: " . genAPIKey() . "\n\n";

///// Encrypt a PIN
//

$pin = '1111'; // Replace this w/ your own PIN
$encryptedPin = aesEncrypt($pin);
echo 'PIN: ' . $pin . ', Encrypted PIN: ' . $encryptedPin . "\n\n";

///// Get your Yubikey tokenId
//
$otp = 'uidhihkfntuibcntdbjccbjubchhgbggldnetdugbdru';
$devId = substr($otp, 0, 12);
echo 'TokenID (b64-encoded): '.modhexToB64($devId)."\n\n";


///// Decrypt a PIN
//

$ct = 'GKE2ZTT0yJ+mG8H6Kauuvg==';
$pin = aesDecrypt($ct);
echo 'PIN: '.$pin."\n\n";

///// Calc a signature
//
$client = 1;
$ci = getClientInfo($client);
$a = array();
$a['id'] = $client;
$a['nonce'] = '12345678';
$a['operation'] = 'add_key';
$h = sign($a, $ci['secret']);
echo 'Secret: '.$ci['secret']."\n";
echo 'Sign: ';
print_r($a);
echo "\nSignature: ".$h."\n";

$a = getdate();
print_r($a);

echo 'Time: '.date(1228287487);
?>
